package com.aizuda.boot.modules.business.permission.controller;

import com.aizuda.boot.modules.business.contract.dto.SingleResponse;
import com.aizuda.boot.modules.business.permission.domain.request.AddPermissionVO;
import com.aizuda.boot.modules.business.permission.domain.request.GetPermissionPageVO;
import com.aizuda.boot.modules.business.permission.domain.request.UpdatePermissionVO;
import com.aizuda.boot.modules.business.permission.domain.response.PagePermissionVO;
import com.aizuda.boot.modules.business.permission.domain.response.PermissionShowVO;
import com.aizuda.boot.modules.business.permission.provider.PermissionProvider;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author duanyao
 * @date 2021/12/15 15:07
 * @description: 权限信息
 */
@Tag(name = "权限管理")
@RequestMapping("/permission")
@RestController
@Validated
@Slf4j
//@LogRecord(module = "权限管理", obj = "权限")
public class PermissionController {

    @Resource
    private PermissionProvider permissionProvider;

    /**
     * 根据权限id查看数据权限
     *
     * @param permissionId
     * @return
     */
    @Operation(summary = "根据权限id查看数据权限")
    @GetMapping("/get/{permissionId}")
    public SingleResponse<PermissionShowVO> getPermission(@PathVariable("permissionId") Long permissionId) {
        return permissionProvider.getPermission(permissionId);
    }

    /**
     * 添加权限
     *
     * @param addPermissionVO
     * @return
     */
    @Operation(summary = "添加权限")
    @PostMapping("/add")
    public SingleResponse<Void> addPermission(@RequestBody AddPermissionVO addPermissionVO) {
        return permissionProvider.addPermission(addPermissionVO);
    }

    /**
     * 修改权限状态
     *
     * @param permissionId
     * @return
     */
    @Operation(summary = "修改权限状态")
    @PutMapping("/enable/{permissionId}")
    public SingleResponse<Void> enable(@PathVariable Long permissionId) {
        return permissionProvider.enable(permissionId);
    }

    /**
     * 修改权限信息
     *
     * @param updatePermissionVO
     * @return
     */
    @Operation(summary = "修改权限信息")
    @PutMapping("/update")
    public SingleResponse<Void> update(@RequestBody UpdatePermissionVO updatePermissionVO) {
        return permissionProvider.updatePermission(updatePermissionVO);
    }

    /**
     * 分页查询权限信息
     *
     * @param PageNo
     * @param PageSize
     * @param vo
     * @return
     */
    @Operation(summary = "获取权限信息列表")
    @PostMapping("/page/{PageNo}/{PageSize}")
    public SingleResponse<IPage<PagePermissionVO>> page(@PathVariable Integer PageNo, @PathVariable Integer PageSize, @RequestBody GetPermissionPageVO vo) {
        IPage<PagePermissionVO> page = new Page<>(PageNo, PageSize);
        return permissionProvider.pagePermission(page, vo);
    }

    @Operation(summary = "删除权限")
    @DeleteMapping("/{permissionId}")
    public SingleResponse<Void> del(@PathVariable Long permissionId) {
        return permissionProvider.del(permissionId);
    }

}


